package com.hejing.object类.Object类之toString方法;

/**
 * ClassName: User
 * Package: com.hejing.object类.Object类之toString方法
 * Description:
 *
 * @Author: HeJing
 * @Create: 2023-03-26 23:13
 * @Version: 1.0
 */
public class User {
    String name;
    int age;

    public User() {
    }

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    // 重写toString()方法:

    /**
     * 方式1: 手动重写toString()方法
     * @return
     */

   /* public String toString() {
        return "姓名: " + this.name + "\t年龄： " + this.age;
    }*/

    // 方式2: 使用IDEA自动生成toString()重写方法


    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}





















